import { Component, OnInit, ViewChild, ViewContainerRef, ComponentRef, ComponentFactoryResolver } from '@angular/core';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
import { LayoutComponent } from "../../../global/layout/layout.component";
import { NotRunningService } from 'app/pages/oldage/list/not-running/not-running.service';
import { PaginationModel } from 'app/widgets/pagination';
import { OldageFileComponent } from "../../modal/file/file.component"
import * as _ from 'lodash';
import { environment } from 'environments/environment';
import { DataService } from '../../../../services/data.service';
import { Util } from 'app/common/util';

@Component({
  selector: 'app-not-running',
  templateUrl: './not-running.component.html',
  styleUrls: ['./not-running.component.scss'],
  providers: [NotRunningService]
})
export class NotRunningComponent implements OnInit {
  // lodash
  public _: any = _;
  //所属地区
  public area: any;
  // 菜单数据
  public menuData: any;
  // 菜单权限set
  public menuResourceSet: any = [];

  public controlTab = false;
  // 组合文件模版
  @ViewChild("file", { read: ViewContainerRef })
  file: ViewContainerRef;
  fileComponent: ComponentRef<OldageFileComponent>;
  //  养老基金列表数据
  public listData;
  // 养老基金列表列表是否全选
  public isCheckedAll = false;
  //  基础信息绑定数据
  public baseInfoPost: any = {
    sFundCode: '',
    sFundName: '',
    sFullName: '',
    sFundType: "7",
    sFundCategory: '',
    sIsQdii: "0",
    sInvestStyle: '',
    sPmAccount: '',
    sPmName: '',
    sListType: "0",
    sExchange: '',
    sBank: '',
    dBankConfirm: '',
    sInvestScope: '',
    sBenchmark: '',
    sManagementFee: '',
    sTrusteeFee: '',
    sOtherFee: '',
    dIssue: '',
    dEstablishment: '',
    sCreator: '',
    sCreatorNo: '',
    sIsRegisterChg: '',
    nRegisterChgNo: '',
    sStatus: '',
    sStatusRunning: '',
    sSubStatus: '',
    sSubStatusSet: '',
    sRemark: '',
    dUpdateTime: '',
    dCreateTime: '',
    sOtherCode1: '',
    sOtherCode2: '',
    sOtherCode3: ''
  };
  // 是否模态框查询
  public isQuery: any = false;
  // 年金分页列表post数据
  public getBody = {
    pageIndex: 1,
    pageSize: 10,
    sStatus: "wyz",
    sFundType: 7,
    sFullName: '',  //组合名称 
    sContractName: '', //合同名称 
    sLinkPrincipalNo: '' //受托人
  }
  public postBody = {
    pageIndex: 1,
    pageSize: 10,
    sStatus: "wyz",
    sFundType: 7,
    sFullName: '',  //组合名称 
    sFundCode: '', //组合代码 
    sContractName: '',  //合同名称 
    sProductType: '',
    sIsAssetTransfer: '0',  //是否资产移交
    sInvestor: '', //移交投管人
    // dSign: '', //签约日期
    // dConfirm: '', //确认日期
    sRecordorgType: '', //备案机构
    sPlanNo: '', //产品登记号
    // dEffective: '', //生效日期
    // dBegin: '', //开始运作日期
    sTermType: '', //期限 
    // dEnd: '', //到期日
    sIsRenewal: '', //是否自动续约
    sLinkPrincipalNo: '', //受托人
    sManager: '', //账管人
    sPrincipal: '', //委托人
    sTrustee: '', //托管人
    sOtherInvestor: '', //其他投资管理人
    sProjectManager: '', //项目经理
    sManagerNo: '', //投资经理
    sBenchmark: '', //业绩比较基准
    sArea: '', //所属地区
    sIsContainRight: '', //是否含权类
    sConfirmationNo: '', //确认函号
    sEmissionObject: '', //发行对象
    sEmissionWay: '' //发行方式
  };
  // 养老基金列表分页配置
  public listPageInfo = {
    currentPageNum: 1,
    pageSize: 10,
    totalPages: 1,
    total: 0,
    pagesShow: 5,
    startRow: 0,
    endRow: 0,
    pageList: [5, 10, 25, 50, 100]
  };
  // 组合/运作审核信息
  public checkInfo: any = {};
  // 开始运作信息
  public startInfo: any = {};
  // 投资经理列表
  public ManagerList;
  // 项目经理列表
  public ProjectManagerList;
  // 开始运作移交投管人
  public runInvestorSelectList: any;
  // 移交投管人
  public sInvestorSelectList: any;
  // 其他投资管理人
  public investorSelectList: any;
  // 项目经理
  public managerSelectList: any;
  // 备案机构、受托人、托管人
  public distionary: any = {
    RECORDORG_TYPE: [],  // 备案机构
    LINK_PRINCIPAL_NO: [],   //受托人
    TRUSTEE: []   //  托管人
  }
  // 字典值
  public dictionaryList: any = {
    // RECORDORG_TYPE: [],  // 备案机构
    TERM_TYPE: [],   // 产品类别
    // LINK_PRINCIPAL_NO: [],   // 受托人
    // TRUSTEE: [],   // 托管人
    MANAGER: [],    // 账管人
    AREA: [],   // 所属地区
    OTHER_INVESTOR: [],  // 其他投资管理人、移交投管人
    EMISSION_WAY: [],  // 发行方式
    STOP_TYPE: [],
    OLDAGE_TYPE: []
  };

  //  optionModel为1时移交投管人显示
  public optionModel = 1;

  constructor(
    public router: Router,
    public resolver: ComponentFactoryResolver,
    public layoutComponent: LayoutComponent,
    public notRunningService: NotRunningService,
    public dataService: DataService
  ) {
    // 用于控制上传附件框是否显示上传、删除文件按钮
    this.dataService.showUploadBtn = false;
  }

  ngOnInit() {
    let that = this;
    // 多选下拉框
    window['$'](".select2").select2();
    this.LoadProjectManagerList();
    this.LoadManagerList();
    this.loadlist();
    // 权限处理
    this.dataService.initTree.subscribe(data => {
      if (data) {
        let SessionMenuData = sessionStorage.getItem('menu');
        this.menuData = JSON.parse(SessionMenuData);
        this.menuResourceSet = [];
        _.forEach(this.menuData, (item, index) => {
          if (item.sName == '养老基金') {
            _.forEach(item.children, (it, idx) => {
              if (it.sName == '未运作') {
                that.menuResourceSet = it.resourceSet;
                sessionStorage.setItem('btn-of', this.menuResourceSet);
              }
            })
          }
        })
      }
    })
    let SessionMenuData = sessionStorage.getItem('menu');
    this.menuData = JSON.parse(SessionMenuData);
    this.menuResourceSet = [];
    _.forEach(this.menuData, (item, index) => {
      if (item.sName == '养老基金') {
        _.forEach(item.children, (it, idx) => {
          if (it.sName == '未运作') {
            that.menuResourceSet = it.resourceSet;
            sessionStorage.setItem('btn-of', this.menuResourceSet);
          }
        })
      }
    })
    // 获取字典值
    this.dictionaryList = JSON.parse(localStorage.getItem("dictionaryList"));
    this.getDictionary();
  }
  ngAfterViewInit() {
    let that = this;
    // 备案机构
    window['$']('#sRecordorgTypeSelected').select2({ width: '190px', tags: true });
    window['$']('#sRecordorgTypeSelected').on("select2:select", function (e) {
      that.postBody.sRecordorgType = window['$']('#sRecordorgTypeSelected').select2("val");
    })
    // 期限
    window['$']('#sTermTypeSelected').select2({ width: '190px' });
    window['$']('#sTermTypeSelected').on("select2:select", function (e) {
      that.postBody.sTermType = window['$']('#sTermTypeSelected').select2("val");
      // 到期日计算
      // if (that.postBody.dEffective == '' || that.postBody.dEffective == null) {
      //   that.postBody.sTermType = '';
      // } else {
      //   if (that.postBody.sTermType == '' || that.postBody.sTermType == null) {
      //     that.postBody.dEnd = '';
      //   } else if (that.postBody.sTermType == '0') {
      //     that.postBody.dEnd = '';
      //     window['$']("#dEnd").attr("disabled", "disabled");
      //     window['$']("#dEnd").css("background", "#eee");
      //   } else {
      //     window['$']("#dEnd").removeAttr("disabled");
      //     window['$']("#dEnd").css("background", "white");
      //     that.postBody.dEnd = Util.dateIncrease(that.postBody.dEffective, that.postBody.sTermType);
      //   }
      // }
    })
    // 受托人
    window['$']('#sLinkPrincipalNoSelected').select2({ width: '190px', tags: true });
    window['$']('#sLinkPrincipalNoSelected').on("select2:select", function (e) {
      that.postBody.sLinkPrincipalNo = window['$']('#sLinkPrincipalNoSelected').select2("val");
    })
    window['$']('#sLinkPrincipalNoSelecteds').select2({ width: '190px', tags: true });
    window['$']('#sLinkPrincipalNoSelecteds').on("select2:select", function (e) {
      that.getBody.sLinkPrincipalNo = window['$']('#sLinkPrincipalNoSelecteds').select2("val");
    })
    // 账管人
    window['$']('#sManagerSelected').select2({ width: '190px' });
    window['$']('#sManagerSelected').on("select2:select", function (e) {
      that.postBody.sManager = window['$']('#sManagerSelected').select2("val");
    })
    // 托管人
    window['$']('#sTrusteeSelected').select2({ width: '190px', tags: true });
    window['$']('#sTrusteeSelected').on("select2:select", function (e) {
      that.postBody.sTrustee = window['$']('#sTrusteeSelected').select2("val");
    })
    // 投资经理
    // window['$']('#sManagerNoSelected').select2({ width: '190px' });
    // window['$']('#sManagerNoSelected').on("select2:select", function (e) {
    //   that.postBody.sManagerNo = window['$']('#sManagerNoSelected').select2("val");
    // })
    // 所属地区
    window['$']('#sAreaSelected').select2({ width: '190px' });
    window['$']('#sAreaSelected').on("select2:select", function (e) {
      that.postBody.sArea = window['$']('#sAreaSelected').select2("val");
    })
    // 组合类型
    window['$']('#sProductTypeSelected').select2({ width: '190px' });
    window['$']('#sProductTypeSelected').on("select2:select", function (e) {
      that.postBody.sProductType = window['$']('#sProductTypeSelected').select2("val");
    })
  }
  create() {
    this.layoutComponent.nav(null, null, "创设·养老基金");
    this.router.navigate(['pages/oldage/new/detail/add']);
  }
  // 判断页面查询还是搜索框查询
  loadcheck(type: any) {
    if (type == 'query') {
      this.isQuery = true;
      this.loadlist(1);
    }
    if (type == 'page') {
      this.isQuery = false;
      this.loadlist(1);
    }
  }
  //  列表数据
  loadlist(pageNum?, pageSize?) {
    let that = this;
    let body: any;
    this.isCheckedAll = false;
    // 判断是页面查询还是搜索框查询
    if (this.isQuery) {
      // 清空页面查询条件
      this.getBody.sFullName = '';
      this.getBody.sContractName = '';
      this.getBody.sLinkPrincipalNo = '';
      window['$']('#sLinkPrincipalNoSelecteds').select2("val", '--请选择--');
      // 转换多选下拉框值
      this.postBody.sInvestor = Util.transferValue('.sInvestor-select');
      this.postBody.sOtherInvestor = Util.transferValue('.investor-select');
      this.postBody.sProjectManager = Util.transferValue('.manager-select');
      // this.postBody.sInvestor = this.ctrlsInvestor();
      // this.postBody.sOtherInvestor = this.ctrlInvestorId();
      // this.postBody.sProjectManager = this.ctrlManagerId();
      // 去空格
      _.forIn(this.postBody, (value, key) => {
        if (key == 'pageSize' || key == 'pageIndex' || key == 'sFundType') {
          // 这里不做处理，排除number类型
        } else {
          that.postBody[key] = _.trim(that.postBody[key]);
        }
      })
      this.postBody.pageIndex = pageNum ? pageNum : this.listPageInfo.currentPageNum;
      this.postBody.pageSize = pageSize ? pageSize : this.listPageInfo.pageSize
      body = _.cloneDeep(this.postBody);
    } else {
      // 去空格
      this.getBody.sFullName = _.trim(this.getBody.sFullName);
      this.getBody.sContractName = _.trim(this.getBody.sContractName);
      this.getBody.pageIndex = pageNum ? pageNum : this.listPageInfo.currentPageNum;
      this.getBody.pageSize = pageSize ? pageSize : this.listPageInfo.pageSize
      body = _.cloneDeep(this.getBody);
    }
    this.notRunningService.list(body).subscribe(data => {
      if (data) {
        this.listData = data.list;
        this.listPageInfo.currentPageNum = data.pageNum;
        this.listPageInfo.totalPages = data.pages;
        this.listPageInfo.total = data.total;
        this.listPageInfo.startRow = data.startRow;
        this.listPageInfo.endRow = data.endRow;
        window['$']('#oldageNotRunQuery').modal('hide');
      }
      //  // 给表格列支持列拖动效果
      //  setTimeout(() => {
      //   Util.colResizable("#fixed-table");
      // }, 100);

      // 给表格列支持列拖动和固定表头效果
      Util.colResizable("#notRunningList");
    });
  }

  // 条数分页
  sizeChange(pageSize: number) {
    if (pageSize !== this.listPageInfo.pageSize) {
      this.listPageInfo.pageSize = pageSize;
      this.loadlist();
    }
  }
  // 列表分页
  pageNavigation(currentPageNum: number) {
    this.listPageInfo.currentPageNum = currentPageNum;
    this.loadlist(this.listPageInfo.currentPageNum, this.listPageInfo.pageSize);
  }
  // 列表全选
  checkedAll() {
    if (this.isCheckedAll) {
      // 更新为全选
      _.forEach(this.listData, item => {
        item.isChecked = true;
      });
    } else {
      // 更新为不全选
      _.forEach(this.listData, item => {
        item.isChecked = false;
      });
    }
  }
  // 列表是否全选
  ctrlCheckAll() {
    let that = this;
    let checkList = [];
    _.forEach(this.listData, item => {
      if (item.isChecked == true) {
        checkList.push(item);
      }
    })
    if (checkList.length == this.listData.length) {
      this.isCheckedAll = true;
    } else {
      this.isCheckedAll = false;
    }
  }
  // 导出
  exportExcel() {
    // let that = this;
    // let checkedItem = [];
    // _.forEach(that.listData, item => {
    //   if (item.isChecked == true) {
    //     checkedItem.push(item.nFundNo);
    //   }
    // });
    // let converItem = checkedItem.join(",");
    // let getBody = {
    //   nFundNoList: converItem,
    //   sStatus: "wyz",
    //   sFundType: 7,
    //   sFullName: '',
    //   sFundCode: ''
    //   // "sIsRegisterChg": that.postBody.sIsRegisterChg
    // };
    // const iframe = window["$"]("<iframe id='downloadiframe'>");
    // iframe.attr("style", "display:none");
    // //  转码，兼容ie
    // getBody.sFullName = encodeURI(getBody.sFullName);
    // iframe.attr(
    //   "src",
    //   environment.server +
    //   "/pms/v1/pension/basicInfo/export/pensionDeptList?token=" +
    //   sessionStorage.getItem("token") +
    //   "&nFundNoList=" +
    //   getBody.nFundNoList +
    //   "&sStatus=" +
    //   getBody.sStatus +
    //   "&sFundType=" +
    //   getBody.sFundType +
    //   "&sFundCode=" +
    //   getBody.sFundCode
    // );
    // window["$"]("body").append(iframe);
    // setTimeout("$('#downloadiframe').remove()", 60000);
    let that = this;
    let checkedItem = [];
    let postBody: any;
    _.forEach(this.listData, item => {
      if (item.isChecked) {
        checkedItem.push(item.nFundNo);
      }
    })
    let converItem = checkedItem.join(",");
    // 请求body
    if (this.isQuery) {
      postBody = _.cloneDeep(this.postBody);
      postBody['nFundNoList'] = checkedItem;
      delete postBody.pageIndex;
      delete postBody.pageSize;
    } else {
      postBody = {
        "nFundNoList": checkedItem,
        "sFullName": this.getBody.sFullName,
        "sContractName": this.getBody.sContractName,
        "sFundType": this.getBody.sFundType,
        "sStatus": this.getBody.sStatus,
        "sLinkPrincipalNo": this.getBody.sLinkPrincipalNo
      }
    }
    // 请求Url
    let postUrl = environment.server + '/pms/v1/pension/basicInfo/export/pensionDeptList?token=' + sessionStorage.getItem('token');
    // 导出
    this.notRunningService.exportTarget(postUrl, postBody, '养老基金组合列表-未运作');
  }

  delProduct() {
    let that = this;
    let checkedItem = [];
    let checkedStatus = [];
    let checkedFundName = [];
    _.forEach(this.listData, item => {
      if (item.isChecked) {
        checkedStatus.push(item.sProductAuditZh);
        checkedFundName.push(item.sFullName);
        checkedItem.push(item.nFundNo);
      }
    });
    let checkedTips = checkedFundName.join("、");
    if (_.includes(checkedStatus, "审核通过")) {
      window["swal"]("提示", "已审核通过的组合不能删除", "warning");
    } else {
      if (checkedItem.length > 0) {
        window["swal"](
          {
            type: "warning",
            showCancelButton: true,
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            showLoaderOnConfirm: true,
            title: "提示",
            text: "<div style='max-height: 200px;overflow-y: auto;'>" + "请确认是否删除：" + checkedTips + "组合" + "</div>",
            html: true
          },
          function (isConfirm) {
            if (isConfirm) {
              let putBody: any = {
                nFundNos: checkedItem
              };
              that.notRunningService.del(putBody).subscribe(data => {
                if (data) {
                  window["swal"]("删除成功！", '', "success");
                  that.loadlist();
                }
              });
            }
          }
        );
      } else {
        window["swal"]("提示", "请选择组合进行删除", "warning");
      }
    }
  }
  // 修改基础信息
  edit(type, item?) {
    let that = this;
    sessionStorage.setItem("parentIndex", "wyz");
    // 组合修改勾选
    let checkProduct = [];
    switch (type) {
      case "dbclick":
        sessionStorage.setItem("currentTitle", "详情·未运作·养老基金");
        that.layoutComponent.nav(null, null, "详情·未运作·养老基金");
        that.router.navigate(['pages/oldage/not-running/detail/edit/' + item.nFundNo]); break;
      case "one":
        _.forEach(that.listData, it => {
          if (it.isChecked == true) {
            checkProduct.push(it);
          }
        });
        if (checkProduct.length < 1) {
          window["swal"]("提示", "请选择一个组合进行查看", "warning");
        }
        if (checkProduct.length == 1) {
          sessionStorage.setItem("currentTitle", "详情·未运作·养老基金");
          that.layoutComponent.nav(null, null, "详情·未运作·养老基金");
          that.router.navigate(['pages/oldage/not-running/detail/edit/' + checkProduct[0].nFundNo]);
        }
        if (checkProduct.length > 1) {
          window["swal"]("提示", "请选择一个组合进行查看", "warning");
        }
        break;
    }
  }
  // 组合/运作审核
  prodAuditing(type) {
    let that = this;
    let checkProduct = [];
    let checkedFundName = [];
    _.forEach(this.listData, item => {
      if (item.isChecked) {
        checkProduct.push(item);
        checkedFundName.push(item.sFullName);
      }
    });
    if (checkProduct.length == 1) {
      // 赋值数据给审核模版
      that.checkInfo = _.cloneDeep(checkProduct[0]);
      if (checkProduct[0].sArea != '' && checkProduct[0].sArea != null && checkProduct[0].sArea != undefined) {
        that.checkInfo.sArea = _.cloneDeep(checkProduct[0].sArea.split(',')[1]);
      }
      switch (type) {
        case 'product':
          if (checkProduct[0].sProductAudit == '0') {
            that.showFile(checkProduct[0]);
            window['$']('#productAudit').modal('show');
            that.showTab()
          } else if (checkProduct[0].sProductAudit == '1') {
            window["swal"]("提示", "该组合已通过组合审核", "warning");
          } else if (checkProduct[0].sProductAudit == '2') {
            window["swal"]("提示", "该组合未通过组合审核，请修改组合信息后重新审核", "warning");
          }
          break;
        case 'start':
          if (checkProduct[0].sRunAudit == '0') {
            window['$']('#startAudit').modal('show');
          } else if (checkProduct[0].sRunAudit == "1") {
            window["swal"]("提示", "该组合已通过运作审核", "warning");
          } else if (checkProduct[0].sRunAudit == "2") {
            window["swal"]("提示", "该组合未通过运作审核，请重新录入开始运作信息", "warning");
          } else if (checkProduct[0].sRunAudit == "3") {
            window["swal"]("提示", "该组合未进行开始运作录入", "warning");
          }
          break;
      }
    } else {
      window["swal"]("提示", "请选择一个组合进行审核操作", "warning");
    }
  }
  // 组合/运作审核
  prductAudit(type, audit) {
    let that = this;
    let checkedTips: any;
    let remindInfo: any;
    if (audit == '1') {
      remindInfo = '通过';
    } else if (audit == '2') {
      remindInfo = '打回';
    }
    let putBody = {
      nFundNo: this.checkInfo.nFundNo,
      auditType: type,
      auditStatus: audit,
      sFundCode: this.checkInfo.sFundCode,
      sFullName: this.checkInfo.sFullName,
      sFundType: '7'
    }
    if (putBody.auditType == 'product') {
      checkedTips = "组合";
    } else {
      checkedTips = "运作";
    }
    window["swal"](
      {
        type: "warning",
        showCancelButton: true,
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        closeOnConfirm: false,
        showLoaderOnConfirm: true,
        title: "提示",
        text: "<div style='max-height: 200px;overflow-y: auto;'>" + "是否确认" + checkedTips + "审核" + remindInfo + "?" + "</div>",
        html: true
      },
      function (isConfirm) {
        if (isConfirm) {
          that.notRunningService.prodAuditing(putBody).subscribe(data => {
            if (data) {
              window["swal"]("审核成功", '', "success");
              that.loadlist();
              that.closeProAudit();
            }
          });
        }
      }
    );
  }


  // 组合/运作审核通过
  passCheck(putBody) {
    let that = this;
    that.notRunningService.prodAuditing(putBody).subscribe(data => {
      if (data) {
        window["swal"]("审核成功", '', "success");
        that.loadlist();
        that.closeProAudit();
      }
    });
  }

  // 开始运作
  showDetail() {
    let that = this;
    let checkProduct = [];
    let checkedStatus = [];
    let checkedFundName = [];
    _.forEach(this.listData, item => {
      if (item.isChecked) {
        checkProduct.push(item);
      }
    });
    if (checkProduct.length == 1) {
      if (checkProduct[0].sProductAudit == '1') {
        if (checkProduct[0].sRunAudit == '1') {
          window["swal"]("提示", "该组合已通过运作审核", "warning");
        } else if (checkProduct[0].sRunAudit == '0') {
          window["swal"]("提示", "该组合正在进行运作审核", "warning");
        } else {
          this.startInfo = _.clone(checkProduct[0]);
          this.runInvestorSelectList = _.split(checkProduct[0].sInvestor, ',');
          window["$"]("#running").modal("show");
          setTimeout(function () {
            window['$'](".runInvestor-select").select2();
          }, 1);
        }
      } else {
        window["swal"]("提示", "该组合未通过组合审核", "warning");
      }
    } else {
      window["swal"]("提示", "请选择一个组合进行开始运作", "warning");
    }
  }
  // 开始运作
  startProduct() {
    let that = this;
    this.startInfo.sInvestor = this.ctrlrunInvestor();
    if (this.requireAdd()) {
      let putBody: any = {
        nFundNo: this.startInfo.nFundNo,
        sFundCode: this.startInfo.sFundCode,
        dBegin: this.startInfo.dBegin,
        sInvestor: this.startInfo.sInvestor,
        sIsAssetTransfer: this.startInfo.sIsAssetTransfer,
        sTransferRemark: this.startInfo.sTransferRemark
      }
      that.notRunningService.startProduct(putBody).subscribe(data => {
        if (data) {
          window["$"]("#running").modal("hide");
          window["swal"]("提示", "开始运作录入成功，请等待审核", "success");
          that.loadlist();
        }
      });
    }
  }
  // 移交投管人
  ctrlTransfer() {
    if (this.startInfo.sIsAssetTransfer == '0') {
      this.startInfo.sInvestor = '';
      window['$']('.runInvestor-select').select2("val", '--请选择--'); // 移交投管人
    }
  }
  // 开始运作必填校验
  requireAdd() {
    let that = this;
    let requiredAddTip = [];
    this.startInfo.sFundCode = _.trim(this.startInfo.sFundCode);
    if (this.startInfo.sFundCode == '' || this.startInfo.sFundCode == null) {
      requiredAddTip.push("组合代码");
    }
    if (this.startInfo.dBegin == '' || this.startInfo.dBegin == null) {
      requiredAddTip.push("开始运作日期");
    }
    if (this.startInfo.sIsAssetTransfer == '1' && (this.startInfo.sInvestor == '' || this.startInfo.sInvestor == null)) {
      requiredAddTip.push("移交投管人");
    }
    if (requiredAddTip.length > 0) {
      let requiredAddTips = requiredAddTip.join("、");
      window['swal']("提示", "请填写:" + requiredAddTips, "warning");
      return false;
    } else {
      return true;
    }
  }
  //关闭组合审核和运作审核模态框
  closeProAudit() {
    window['$']('#productAudit').modal('hide');
    window['$']('#startAudit').modal('hide');
  }
  // 组合信息模版
  showFile(item) {
    this.dataService.sLinkPrincipalNo = '';
    this.dataService.sLinkPrincipal = ''
    // 判断组件是否已创建，如果创建先注销
    if (this.fileComponent && this.fileComponent.instance) {
      this.fileComponent.destroy();
    }
    console.log(item);
    this.dataService.sLinkPrincipalNo = '';
    this.dataService.sLinkPrincipal = ''
    const fileComponent = this.resolver.resolveComponentFactory(OldageFileComponent);
    this.dataService.sLinkPrincipalNo = item.sLinkPrincipalNo
    console.log('item.sLinkPrincipalNo')
    console.log(this.dataService.sLinkPrincipalNo)
    this.dataService.sLinkPrincipal = item.sLinkPrincipalNoZh
    console.log('this.dataService.sLinkPrincipal')
    console.log(this.dataService.sLinkPrincipal)
    this.fileComponent = this.file.createComponent(fileComponent);
    this.fileComponent.instance.nFundNo = item.nFundNo;
    this.fileComponent.instance.sAttachType = item.sAttachType;
    this.fileComponent.instance.sAttachCode = item.sAttachCode;
  }
  //关闭审核模态框
  showTab() {
    window['$']('#info').removeClass('active');
    window['$']('#tab_1').removeClass('active');
    window['$']("#info_Content").attr('aria-expanded', "false");
    window['$']('#file').removeClass('active');
    window['$']('#tab_2').removeClass('active');
    window['$']("#file_Content").attr('aria-expanded', "false");

    window['$']('#info').addClass('active');
    window['$']('#tab_1').addClass('active');
    window['$']("#info").attr('aria-expanded', "true");
  }
  // 显示搜索模态框
  showQuery() {
    window['$']('#oldageNotRunQuery').modal('show');
  }
  // 重置搜索
  resetQuery() {
    this.postBody.sFundCode = ''; //组合代码 
    this.postBody.sFullName = '';  //组合名称 
    this.postBody.sContractName = '';  //合同名称 
    this.postBody.sIsAssetTransfer = '0';  //是否资产移交
    this.postBody.sInvestor = '';
    //this.postBody.dSign = ''; //签约日期
    //this.postBody.dConfirm = ''; //确认日期
    this.postBody.sRecordorgType = ''; //备案机构
    this.postBody.sPlanNo = ''; //产品登记号
    this.postBody.sConfirmationNo = ''; //确认函号
    this.postBody.sEmissionObject = ''; //发行对象
    this.postBody.sEmissionWay = ''; //发行方式
    //this.postBody.dEffective = ''; //生效日期
    //this.postBody.dBegin = ''; //开始运作日期
    this.postBody.sTermType = ''; //期限 
    //this.postBody.dEnd = ''; //到期日
    this.postBody.sIsRenewal = ''; //是否自动续约
    this.postBody.sLinkPrincipalNo = ''; //受托人
    this.postBody.sManager = ''; //账管人
    this.postBody.sPrincipal = ''; //委托人
    this.postBody.sTrustee = ''; //托管人
    this.postBody.sOtherInvestor = ''; //其他投资管理人
    this.postBody.sProjectManager = ''; //项目经理
    this.postBody.sManagerNo = ''; //投资经理
    this.postBody.sBenchmark = ''; //业绩比较基准
    this.postBody.sArea = ''; //所属地区
    this.postBody.sIsContainRight = ''; //是否含权类
    window['$']('#sRecordorgTypeSelected').select2("val", '--请选择--'); // 备案机构
    window['$']('#sTermTypeSelected').select2("val", '--请选择--'); // 期限
    window['$']('#sLinkPrincipalNoSelected').select2("val", '--请选择--'); // 受托人   
    window['$']('#sManagerSelected').select2("val", '--请选择--'); // 账管人
    window['$']('#sTrusteeSelected').select2("val", '--请选择--'); // 托管人
    // window['$']('#sManagerNoSelected').select2("val", '--请选择--'); // 投资经理
    window['$']('#sAreaSelected').select2("val", '--请选择--'); // 所属地区
    window['$']('#sProductTypeSelected').select2("val", '--请选择--'); // 组合类型
    window['$']('.sInvestor-select').select2("val", '--请选择--'); // 移交投管人
    window['$']('.investor-select').select2("val", '--请选择--'); // 其他投资管理人
    window['$']('.manager-select').select2("val", '--请选择--'); // 项目经理
  }
  // 是否资产移交控制
  IsAssetTransfer() {
    let that = this;
    if (this.postBody.sIsAssetTransfer == '0') {
      this.postBody.sInvestor = '';
      window['$']('.sInvestor-select').select2("val", '--请选择--'); // 移交投管人
    }
  }
  //获取基金经理下拉框数据
  LoadManagerList() {
    let that = this;
    that.notRunningService.getManagerList().subscribe(data => {
      if (data) {
        that.ManagerList = data;
      }
    });
  }
  //获取基金经理下拉框数据
  LoadProjectManagerList() {
    let that = this;
    that.notRunningService.getProjectManagerList().subscribe(data => {
      if (data) {
        that.ProjectManagerList = data;
      }
    });
  }
  // 移交投管人sInvestor
  ctrlrunInvestor() {
    let investorList: any;
    let investorChecked = [];
    let selected = window['$']('.runInvestor-select').val();
    _.forEach(selected, item => {
      let index1 = item.indexOf("'");
      let index2 = item.lastIndexOf("'");
      let sales = item.substring(index1 + 1, index2);
      investorChecked.push(sales);
    })
    investorList = investorChecked.join(",");
    return investorList;
  }
  // 移交投管人sInvestor
  ctrlsInvestor() {
    let investorList: any;
    let investorChecked = [];
    let selected = window['$']('.sInvestor-select').val();
    _.forEach(selected, item => {
      let index1 = item.indexOf("'");
      let index2 = item.lastIndexOf("'");
      let sales = item.substring(index1 + 1, index2);
      investorChecked.push(sales);
    })
    investorList = investorChecked.join(",");
    return investorList;
  }
  // 其他投资管理人
  ctrlInvestorId() {
    let investorIdList: any;
    let investorChecked = [];
    let selected = window['$']('.investor-select').val();
    _.forEach(selected, item => {
      let index1 = item.indexOf("'");
      let index2 = item.lastIndexOf("'");
      let sales = item.substring(index1 + 1, index2);
      investorChecked.push(sales);
    })
    investorIdList = investorChecked.join(",");
    return investorIdList;
  }
  // 项目经理
  ctrlManagerId() {
    let managerIdList: any;
    let managerChecked = [];
    let selected = window['$']('.manager-select').val();
    _.forEach(selected, item => {
      let index1 = item.indexOf("'");
      let index2 = item.lastIndexOf("'");
      let sales = item.substring(index1 + 1, index2);
      managerChecked.push(sales);
    })
    managerIdList = managerChecked.join(",");
    return managerIdList;
  }
  // 点击表格头排序
  orderData(colName) {
    let listDataAsc = _.orderBy(this.listData, [colName], ["asc"]);
    if (JSON.stringify(this.listData) == JSON.stringify(listDataAsc)) {
      listDataAsc = _.orderBy(this.listData, [colName], ["desc"]);
    }
    this.listData = listDataAsc;
  }
  OnAreaChg(event) {

    if (event[1] == '--请选择--' && event[0] != '--请选择--') {
      this.postBody.sArea = this.postBody.sArea + ',' + event[0]
    } else if (event[0] == '--请选择--') {
      this.postBody.sArea = '';
    } else {
      this.postBody.sArea = this.postBody.sArea + ',' + event[0] + "-" + event[1]
    }
    // console.log("纳尼"+this.postBody.sArea)

  }
  OnAreaCodeChg(event) {

    this.postBody.sArea = event;
  }
  // 获取备案机构、受托人、托管人下拉框值
  getDictionary() {
    let that = this;
    this.notRunningService.getDictionary().subscribe(data => {
      if (data) {
        that.distionary.RECORDORG_TYPE = data.RECORDORG_TYPE;
        that.distionary.LINK_PRINCIPAL_NO = data.LINK_PRINCIPAL_NO;
        that.distionary.TRUSTEE = data.TRUSTEE;
      }
    })
  }
}
